package com.mnyc.research.controller;

import java.util.List;
import javax.annotation.PostConstruct;
import javax.servlet.http.HttpServletResponse;

import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.mnyc.common.annotation.Log;
import com.mnyc.common.core.controller.BaseController;
import com.mnyc.common.core.domain.AjaxResult;
import com.mnyc.common.enums.BusinessType;
import com.mnyc.research.domain.JyTeacher;
import com.mnyc.research.service.IJyTeacherService;
import com.mnyc.common.utils.poi.ExcelUtil;
import com.mnyc.common.core.page.TableDataInfo;

/**
 * 教师信息Controller
 *
 * @author wdy
 * @date 2025-08-04
 */
@RestController
@RequestMapping("/research/jyTeacher")
public class JyTeacherController extends BaseController {
    @Autowired
    private IJyTeacherService jyTeacherService;

    /**
     * 查询教师信息列表
     */
    @PreAuthorize("@ss.hasPermi('research:jyTeacher:list')")
    @GetMapping("/list")
    public TableDataInfo list(JyTeacher jyTeacher) {
        startPage();
        List<JyTeacher> list = jyTeacherService.selectJyTeacherList(jyTeacher);
        return getDataTable(list);
    }

    /**
     * 导出教师信息列表
     */
    @PreAuthorize("@ss.hasPermi('research:jyTeacher:export')")
    @Log(title = "教师信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, JyTeacher jyTeacher) {
        List<JyTeacher> list = jyTeacherService.selectJyTeacherList(jyTeacher);
        ExcelUtil<JyTeacher> util = new ExcelUtil<JyTeacher>(JyTeacher.class);
        util.exportExcel(response, list, "教师信息数据");
    }

    /**
     * 获取教师信息详细信息
     */
    @PreAuthorize("@ss.hasPermi('research:jyTeacher:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return success(jyTeacherService.selectJyTeacherById(id));
    }

    /**
     * 新增教师信息
     */
    @PreAuthorize("@ss.hasPermi('research:jyTeacher:add')")
    @Log(title = "教师信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody JyTeacher jyTeacher) {
        return toAjax(jyTeacherService.insertJyTeacher(jyTeacher));
    }

    /**
     * 修改教师信息
     */
    @PreAuthorize("@ss.hasPermi('research:jyTeacher:edit')")
    @Log(title = "教师信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody JyTeacher jyTeacher) {
        return toAjax(jyTeacherService.updateJyTeacher(jyTeacher));
    }

    /**
     * 删除教师信息
     */
    @PreAuthorize("@ss.hasPermi('research:jyTeacher:remove')")
    @Log(title = "教师信息", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(jyTeacherService.deleteJyTeacherByIds(ids));
    }

    /**
     * 通过教研组Id查询该教研组的老师
     */
    @GetMapping(value = "/groupId/{groupId}")
    public TableDataInfo getLListByGroupId(@PathVariable("groupId") Long groupId,JyTeacher jyTeacher) {
        startPage();
        List<JyTeacher> list = jyTeacherService.selectJyTeacherByGroupId(groupId,jyTeacher);
        return getDataTable(list);
    }
}
